import PySide6
from PySide6.QtCore import qVersion
import pyautogui
import keyboard  # 需要安装 keyboard 库
import time
import ctypes
import sys


def get_version(): # function to get PySide6 and Qt versions

    print("PySide6 version:", PySide6.__version__)
    print("Qt version:", qVersion())
    print("Python version:", sys.version)


def collect_coordinates():
    '''
    创建恐龙 坐标 250 28
    恐龙仓库 坐标 420 28
    
    '''

    print("坐标收集器已启动！")
    print("将鼠标移动到目标位置，按下 's' 键记录坐标，按下 'q' 键退出。")

    coordinates = []  # 用于存储收集的坐标

    try:
        while True:
            # 获取当前鼠标位置
            x, y = pyautogui.position()
            print(f"当前鼠标位置: ({x}, {y})", end="\r")  # 实时显示坐标

            # 检测按键
            if keyboard.is_pressed('s'):  # 按下 's' 键记录坐标
                coordinates.append((x, y))
                print(f"\n已记录坐标: ({x}, {y})")
                time.sleep(0.3)  # 防止重复记录

            if keyboard.is_pressed('q'):  # 按下 'q' 键退出
                print("\n坐标收集结束！")
                break

            time.sleep(0.1)  # 降低 CPU 占用

    except KeyboardInterrupt:
        print("\n程序被手动中断。")

    return coordinates

def get_physical_resolution(): # 获取物理dpi
    if sys.platform != 'win32':
        raise OSError("This function only works on Windows")

    try:
        # 强制启用最高DPI识别级别（Windows 8.1+）
        ctypes.windll.shcore.SetProcessDpiAwareness(2)
    except:
        try:
            # 备用方案：旧版Windows DPI识别（Vista+）
            ctypes.windll.user32.SetProcessDPIAware()
        except:
            pass

    # 直接通过显示设备获取原生分辨率
    hdc = ctypes.windll.user32.GetDC(0)
    real_width = ctypes.windll.gdi32.GetDeviceCaps(hdc, 118)  # DESKTOPHORZRES
    real_height = ctypes.windll.gdi32.GetDeviceCaps(hdc, 117)  # DESKTOPVERTRES
    ctypes.windll.user32.ReleaseDC(0, hdc)
    
    return (real_width, real_height)

# 运行坐标收集函数
if __name__ == "__main__":
    
    get_version()


